<?php if (!defined('BASEPATH')) {
	exit('No direct script access allowed');
}

class Ar_zones_model extends CI_Model {
	public function __construct() {
		parent::__construct();
	}

	public function get_zones(){
		return $this->db->query('SELECT * FROM ar_zones')->result();
	}

	public function getzone($code){
		return $this->db->query('SELECT * FROM ar_zones WHERE zone_code = "'.$code.'"')->result();
	}

	public function getzoneval($code){
		return $this->db->query('SELECT * FROM ar_zone_values WHERE zone_code = "'.$code.'"')->result();
	}

	public function getzonechild($id){
		return $this->db->query('SELECT * FROM ar_zone_values WHERE parent_value_id = "'.$id.'"')->result();
	}

	public function savezones($data){
		$this->db->query('call ar_zone_values_ins(?,?,?,?,?,?,@err,@msg,@id)',$data);
		$que = $this->db->query("SELECT @id as id,@err as err,@msg as msg");
        $id; $msg; $err;
        foreach($que->result() as $keys){
          $msg = $keys->msg;
          $err = $keys->err;
          $id = $keys->id;
        }
        $arr = array(
            'msg'   =>$msg,
            'err'   =>$err,
            'id'	=>$id
        );
        return $arr;
	}

	public function save($data){
		$this->db->query('call ar_zones_upd(?,?,?,?,@err,@msg)',$data);
		$que = $this->db->query("SELECT @err as err,@msg as msg");
        $id; $msg; $err;
        foreach($que->result() as $keys){
          $msg = $keys->msg;
          $err = $keys->err;
        }
        $arr = array(
            'msg'   =>$msg,
            'err'   =>$err
        );
        return $arr;
	}

	public function editchild($data){
		$this->db->query('call ar_zone_values_upd(?,?,?,?,?,@err,@msg)',$data);
		$que = $this->db->query("SELECT @err as err,@msg as msg");
        $id; $msg; $err;
        foreach($que->result() as $keys){
          $msg = $keys->msg;
          $err = $keys->err;
        }
        $arr = array(
            'msg'   =>$msg,
            'err'   =>$err
        );
        return $arr;
	}

}